<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>细节视图对齐</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="bootstrap/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="bootstrap/js/html5shiv.min.js"></script>
    <script src="bootstrap/js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<h1>使用<code>detailViewAlign</code>选项对齐详细视图图标。</h1>
<div class="toolbar">
    <label class="checkbox-inline">
        <input type="radio" name="detailViewAlign" value="left">
        <code>left</code>
    </label>
    <label class="checkbox-inline">
        <input type="radio" checked name="detailViewAlign" value="right">
        <code>right</code>
    </label>
</div>

<table
        id="table"
        data-height="460"
        data-detail-view="true"
        data-detail-filter="detailFilter"
        data-show-footer="true"
        data-toolbar=".toolbar"
        data-url="json/data1.json">
    <thead>
    <tr>
        <th data-field="id" data-valign="middle" rowspan="2" data-footer-formatter="idFormatter">ID</th>
        <th colspan="2">Detail</th>
    </tr>
    <tr>
        <th data-field="name" data-footer-formatter="footerFormatter">Item Name</th>
        <th data-field="action" data-formatter="actionFormatter" data-events="actionEvents" data-footer-formatter="footerFormatter">Action</th>
    </tr>
    </thead>
</table>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="bootstrap/js/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="bootstrap/js/bootstrap-table.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script src="bootstrap/js/bootstrap-table-zh-CN.min.js"></script>
<script>
    var $table = $('#table')

    window.actionEvents = {
        'click .btn': function () {
            alert('Click')
        }
    }

    $(function() {
        $('.toolbar input').change(function () {
            var detailViewAlign = $('.toolbar input:checked').val()

            $table.bootstrapTable('refreshOptions', {
                detailViewAlign: detailViewAlign
            })
        })

        $table.bootstrapTable({
            detailViewAlign: 'right'
        })
    })

    function detailFilter(index) {
        return index % 2 === 0
    }

    function idFormatter() {
        return 'Total'
    }

    function footerFormatter(data) {
        return data.length
    }

    function actionFormatter() {
        return '<button class="btn btn-secondary">Click</>'
    }
</script>
</body>
</html>